from socket import *
from select import *

# Make an internet socket, TCP connection mode
s = socket(AF_INET,SOCK_STREAM)
# Bind locally, port 9999
s.bind(('', 6010))
# Start listening, only accept up to 32 connections
s.listen(32)
# Until we feel like stopping,

connection=[s]

while(True):
	r, w, e = select(connection, [], [])
	if r[0] == s:
		(conn, addr) = r[0].accept()
		connection += [conn]
	else:
		message = r[0].recv(1000)
		print message
		for i in range(1,len(connection)):
			connection[i].send(message+'\n')
	#n = conn.recv(3)
	#conn.send(str(int(n) + 1) + '\n')
	#conn.close()
	#if n == '0':
	#    break

